/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>微信设置</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form
      style="margin-top: 20px"
      label-width="200px"
      :model="editForm"
      :rules="rules"
      ref="editForm"
    >
      <el-form-item label="微信公众号(AppId):" prop="deptNo">
        <el-input
          size="small"
          v-model="editForm.appid"
          auto-complete="off"
          placeholder="请输入微信公众号AppId"
        ></el-input>
      </el-form-item>
      <el-form-item label="微信公众号(Secret):" prop="deptNo">
        <el-input
          size="small"
          v-model="editForm.secret"
          auto-complete="off"
          placeholder="请输入微信公众号Secret"
        ></el-input>
      </el-form-item>

      <el-form-item label="微信公众号商户号id:">
        <el-input
          size="small"
          v-model="editForm.mchid"
          auto-complete="off"
          placeholder="请输入微信微信公众号商户号id"
        ></el-input>
      </el-form-item>

      <el-form-item label="微信公众号商户号key:">
        <el-input
          size="small"
          v-model="editForm.tenpaykey"
          auto-complete="off"
          placeholder="请输入微信微信公众号商户号key"
        ></el-input>
      </el-form-item>

      <el-form-item label="微信公众号回调URl:">
        <el-input
          size="small"
          v-model="editForm.url"
          auto-complete="off"
          placeholder="请输入微信公众号回调URl"
        ></el-input>
      </el-form-item>
      <hr />
      <el-form-item label="微信公众号Token:">
        <el-input
          size="small"
          v-model="editForm.wxtoken"
          auto-complete="off"
          placeholder="请输入微信公众号回调URl"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center">
      <el-button size="small" @click="reset">重置</el-button>
      <el-button
        size="small"
        type="primary"
        class="title"
        @click="submitForm('editForm')"
        >保存</el-button
      >
    </div>
    <!-- 编辑界面 -->
  </div>
</template>

<script>
import { req } from "@/api/axiosFun";
export default {
  data() {
    return {
      //定义loading默认为false
      logining: "",
      editForm: {
        appid: "",
        secret: "",
        mchid: "",
        tenpaykey: "",
        url: "",
        wxtoken: "",
      },
      // rules表单验证
      rules: {
        deptNo: [
          {
            required: true,
            message: "请输入微信公众号相关参数",
            trigger: "blur",
          },
        ],
      },
    };
  },
  // 注册组件
  components: {},
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.load();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    submitForm(formName) {
      if (this.$jsutils.isempty(this.editForm.appid)) {
        this.$message.error("微信公众号的appid不能为空！");
        return false;
      }
      if (this.$jsutils.isempty(this.editForm.secret)) {
        this.$message.error("微信公众号的secret不能为空！");
        return false;
      }

      this.$confirm("确认要提交数据吗？").then(() => {
        this.logining = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });

        req("post", "/WxOperationApi/WXConfig?token="+this.$jsutils.sessionget("token"), {
          model: JSON.stringify(this.editForm),
        })
          .then((res) => {
            this.logining.close();
            if (res.success) {
              this.$message.success("操作成功");
              this.load();
            } else {
              this.$message.error(res.data);
              return false;
            }
          })
          .catch(() => {
            this.logining.close();
          });
      });
    },
    reset() {
      this.editForm.appid = "";
      this.editForm.secret = "";
      this.editForm.mchid = "";
      this.editForm.tenpaykey = "";
      this.editForm.url = "";
      this.editForm.wxtoken = "";
    },
    load() {
      this.logining = true;

      req("post", "/WxOperationApi/GetWXConfig?token="+this.$jsutils.sessionget("token"), {
      }).then((res) => {
        this.logining = false;
        if (res.success) {
          this.editForm.appid = res.data.appid;
          this.editForm.secret = res.data.secret;
          this.editForm.mchid = res.data.mch_id;
          this.editForm.tenpaykey = res.data.paysignkey;
          this.editForm.url = res.data.url;
          this.editForm.wxtoken = res.data.Token;
        } else {
          this.$message.error(res.data);
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 